Program on doGet and doPost
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Sample extends HttpServlet
{
public void init(ServletConfig conf)throws ServletException
{
Super.init(conf);
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<html> ");
pw.println("<head></head> ");
pw.println("<body bgcolor=red> ");
pw.println("<h1>Method Called”+req.getMethod()+” </h1> ");
pw.println("</body> ");
pw.println("</html> ");
pw.close();
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<html> ");
pw.println("<head></head> ");
pw.println("<body bgcolor=red> ");
pw.println("<h1> Method “+req.getMethod()+”</h1> ");
pw.println("</body> ");
pw.println("</html> ");
pw.close();
}
}
Sample.html
<html>
<head></head>
<form name=”f1” action=”http://localhost/8080/Sample” method=”get”>
<input type=”submit”>
</form>
</html>